﻿using HalconDotNet;
using Halcon二次开发.Model;
using Halcon二次开发.View.多文本显示工具;
using Halcon二次开发.View.文本显示工具;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Halcon二次开发.Controller.多文本显示
{
    public class ShowTextController
    {
        private HSmartWindowControl hw;
        //输入的X坐标
        public double[] IntputRows;
        //输入Y坐标
        public double[] IntputColumns;
        //输入的角度
        public double[] IntputAngles;
        //窗体的对象
        public MessageBoxStringsForms MessageBoxStringsForms;
        //输入显示的数组
        public double[] IntputDoubleTexts;
        public ShowTextController()
        {
            //获取当前工位的HSmartWindowControl对象
            hw = StaicResouce.HwindowFlowNodeUrse.hSmartWindowControl1;
        }
        public void Run()
        {
            if (IntputRows!=null&&IntputRows.Length>0)
            {
                for (int i = 0; i < IntputRows.Length; i++)
                {
                    MessageBoxStringsForms = GetForm() as MessageBoxStringsForms;
                    HOperatorSet.SetTposition(hw.HalconWindow, IntputRows[i]+(double)MessageBoxStringsForms.numericUpDown2.Value, IntputColumns[i] + (double)MessageBoxStringsForms.numericUpDown1.Value);
                    HOperatorSet.SetFont(hw.HalconWindow, MessageBoxStringsForms.textBox3.Text+ "-Normal-"+MessageBoxStringsForms.textBox4.Text.Trim());
                    HOperatorSet.SetColor(hw.HalconWindow,MessageBoxStringsForms.textBox2.Text.Trim());
                    HOperatorSet.WriteString(hw.HalconWindow, MessageBoxStringsForms.textBox1.Text+ IntputDoubleTexts[i].ToString("F3"));
                }
            }
        }
        public Form GetForm()
        {
            foreach (TreeNode node in StaicResouce.HwindowFlowNodeUrse.treeView1.Nodes)
            {
                if (node.Nodes.Count == 0) continue;
                if (node.Nodes[0].Tag == this)
                {
                    return (node.Tag as Form);

                }
            }
            return null;
        }
    }
}
